<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text"><button>按钮</button>
    <div></div>
    <script>
        // trim() 可去除字符首尾的空格 字符中间的不去除 返回一个新的字符串 需要声明接收
        // 可去除 用户在提交表单首尾有空格的需求
        var ipt = document.querySelector('input')
        var btn = document.querySelector('button')
        var div = document.querySelector('div')
        btn.onclick = function () {
            var str = ipt.value.trim()
            if (str == '') {
                alert('请输入内容')
            } else {
              console.log(str);

            }
        }

    </script>

</body>

</html>